//
//  SplashScene.m
//  Project 5
//
//  Created by Nguyen Tan Loc on 7/6/13.
//  Copyright (c) 2013 Nguyen Tan Loc. All rights reserved.
//

#import "SplashScene.h"
#import "MenuScene.h"

@implementation SplashScene


+(CCScene *) scene
{
	CCScene *scene = [CCScene node];
	SplashScene *layer = [SplashScene node];
	[scene addChild: layer];
	return scene;
}


-(id) init
{
	if(self = [super init])
    {
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"variousSprites@2x.plist" textureFilename:@"variousSprites@2x.png"];
        
        CGSize winSize = [[CCDirector sharedDirector] winSize];
        CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:FRAME_NAME_SPLASH];
        [sprite setOpacity:0];
        [sprite setAnchorPoint:ccp(0.5, 0.5)];
        [sprite setPosition:ccp(winSize.width / 2, winSize.height / 2)];
        [self addChild:sprite];
        
        CCFadeTo *fadeTo = [CCFadeTo actionWithDuration:0.2 opacity:255];
        CCDelayTime *delayTime = [CCDelayTime actionWithDuration:0.2];
        CCCallFunc *callFunc = [CCCallFunc actionWithTarget:self selector:@selector(changeScene)];
        CCSequence *sequence = [CCSequence actions:fadeTo, delayTime, callFunc, nil];
        
        [sprite runAction:sequence];
	}
    
	return self;
}

-(void) changeScene
{
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MenuScene scene]]];
}

-(void) dealloc
{
    [super dealloc];
}
@end
